
APIBase = function(){

    base = new Object();

    base.token = getUserToken();

    base.HOST = 'http://rest.lovepinyao.com/manager/';
    //base.HOST = 'http://127.0.0.1:8081/manager/';

    base.API_HOST = 'http://rest.lovepinyao.com/';
    //base.API_HOST = 'http://127.0.0.1:8081/';


    base.table_get = function(path,pars,callback){
        $.ajax({
            url:base.HOST + path,
            data:pars,
            type:'get',
            dataType:'json',
            beforeSend: function(request) {
                request.setRequestHeader("X-Access-Code", "lovepinyaoaccesscode");
                request.setRequestHeader("X-Access-Key", "lovepinyaoaccesskey");
            },
            success:function(msg){
                if(msg.code == 200){
                    if(typeof(msg.results) != 'undefined'){
                        return callback(path,msg.results,true)
                    }else{
                        return callback(path,[],true);
                    }
                }else{
                    return callback(path,msg.message,false);
                }
            }
        });
    };

    base.api_table_get = function(path,pars,callback){
        $.ajax({
            url:base.API_HOST + path,
            data:pars,
            type:'get',
            dataType:'json',
            beforeSend: function(request) {
                request.setRequestHeader("X-Access-Code", "lovepinyaoaccesscode");
                request.setRequestHeader("X-Access-Key", "lovepinyaoaccesskey");
            },
            success:function(msg){
                if(msg.code == 200){
                    if(typeof(msg.results) != 'undefined'){
                        return callback(path,msg.results,true)
                    }else{
                        return callback(path,[],true);
                    }
                }else{
                    return callback(path,msg.message,false);
                }
            }
        });
    };

    base.get = function(path,pars,dataBack){
        $.ajax({
            url:base.HOST + path,
            data:pars,
            type:'get',
            dataType:'json',
            beforeSend: function(request) {
                request.setRequestHeader("X-Access-Code", "lovepinyaoaccesscode");
                request.setRequestHeader("X-Access-Key", "lovepinyaoaccesskey");
            },
            success:function(msg){
                console.log("APIBase 打印:");
                console.log(msg);
                if(msg.code == 200){
                    if(typeof(msg.results) != 'undefined'){
                        return dataBack(msg.results,true)
                    }else{
                        return dataBack({},true)
                    }
                }else{
                    return dataBack(msg.message,false);
                }
            }
        });
    };

    base.api_get = function(path,pars,dataBack){
        $.ajax({
            url:base.API_HOST + path,
            data:pars,
            type:'get',
            dataType:'json',
            beforeSend: function(request) {
                request.setRequestHeader("X-Access-Code", "lovepinyaoaccesscode");
                request.setRequestHeader("X-Access-Key", "lovepinyaoaccesskey");
            },
            success:function(msg){
                console.log("APIBase 打印:");
                console.log(msg);
                if(msg.code == 200){
                    if(typeof(msg.results) != 'undefined'){
                        return dataBack(msg.results,true)
                    }else{
                        return dataBack({},true)
                    }
                }else{
                    return dataBack(msg.message,false);
                }
            }
        });
    };

    base.post = function(path,pars,dataBack){
        $.ajax({
            url:base.HOST + path,
            data:pars,
            type:'post',
            dataType:'json',
            beforeSend: function(request) {
                request.setRequestHeader("X-Access-Code", "lovepinyaoaccesscode");
                request.setRequestHeader("X-Access-Key", "lovepinyaoaccesskey");
            },
            success:function(msg){
                if(msg.code == 200){
                    if(typeof(msg.results) != 'undefined'){
                        return dataBack(msg.results,true)
                    }else{
                        return dataBack({},true)
                    }
                }else{
                    return dataBack(msg.message,false);
                }

            }
        });
    };

    base.api_post = function(path,pars,dataBack){
        $.ajax({
            url:base.API_HOST + path,
            data:pars,
            type:'post',
            dataType:'json',
            beforeSend: function(request) {
                request.setRequestHeader("X-Access-Code", "lovepinyaoaccesscode");
                request.setRequestHeader("X-Access-Key", "lovepinyaoaccesskey");
            },
            success:function(msg){
                if(msg.code == 200){
                    if(typeof(msg.results) != 'undefined'){
                        return dataBack(msg.results,true)
                    }else{
                        return dataBack({},true)
                    }
                }else{
                    return dataBack(msg.message,false);
                }

            }
        });
    };



    return base;
};



